import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const state = {
	count: 40
}
const getters = {
	count:function(state){
		return state.count +=10
	}
}
const mutations = {
	add (state,data) {
		state.count += data.n
	},
	sub (state) {
		state.count --
	}
}
const actions = {
	actionSub (context) {
		context.commit('sub')
	},
	async actionAdd ({dispatch,commit},obj) {
		await dispatch('actionSub')
		commit(obj)
	},
}

const moduleA = {
	state,
	// getters,
	mutations,
	actions
}
const moduleB ={
	state:{
		count:80
	},
	mutations: {
		addB (state,data) {
			state.count += data.n
		},
		sub (state) {
			state.count -=5
		}
	}
}
export default new Vuex.Store({
	modules: {
		a: moduleA,
		b: moduleB
	},

	// state,
	// // getters,
	// mutations,
	// actions
})